'''
Created on Mar 4, 2012

@author: kafkef
'''


from PyQt4.QtGui import *

from dexen.system.server.action_mgr import Action
from dexen.system.common.transact import Transaction


class ActionInfoDlg(QDialog):
    def __init__(self, action, parent):
        QDialog.__init__(self, parent)
        self.action = action
        self.setWindowTitle("Transaction Info")
        self.setModal(True)
        self._create_widgets()

    def _create_text_edit(self):
        text_edit = QTextEdit()
        #text_edit.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
        #print "I am in create text edit"
        return text_edit

    def _create_widgets(self):
        action = self.action
        assert isinstance(action, Action)
        transact = action.get_transact()
        assert isinstance(transact, Transaction)
        
        v_layout = QVBoxLayout()
        h_layout = QHBoxLayout()
        
        f_layout = QFormLayout()
        f_layout.addRow("Time Stamp:", QLabel(str(action.get_id())))
        f_layout.addRow("Transaction Id:", QLabel(str(transact.get_id())))
        f_layout.addRow("Transaction Type:", QLabel(transact.get_type()))
        f_layout.addRow("Execution Node:", QLabel(transact.get_exec_node_name()))
        
        h_layout.addLayout(f_layout)
        
        vv_layout = QVBoxLayout()
        vv_layout.addWidget(QLabel("Individuals"))
        
        v_layout.addLayout(h_layout)
        
        if (action.is_receive()):
            v_layout.addWidget(QLabel("Stdout:"))
            text_edit = self._create_text_edit()
            text_edit.setText(transact.get_out_msg())
            v_layout.addWidget(text_edit)
            v_layout.addWidget(QLabel("Stderr:"))
            text_edit = self._create_text_edit()
            text_edit.setText(transact.get_err_msg())
            v_layout.addWidget(text_edit)
            
        self.setLayout(v_layout)
